home *** CD-ROM | disk | FTP | other *** search
- char *ckzv = "File access CTOS/BTOS Version-2.00, Sep 1991";
-
- /* Joel Dunn, UNC-CH Administrative Data Processing */
- /* Modification Joel Dunn, 9/21/87
- zchki returns an integer filesize, thus
- it had problems for >32K. Converted size to Kbytes */
-
- /* Modification Doug Drury ITT-Federal Services Corp 6/91
- ZCLOSE checked file pointer to see if it is pointing to origional
- vidio file pointer. If it is, the file is not closed. This fixes
- a problem that existed with the remote and remote host commands. After
- a remote or remote host was executed, the file pointer to the local
- vidio was closed */
-
- char *ckzsys = " CTOS 10.3 Standard Software";
- /* Definitions of some Unix system commands, retain during conversion */
-
- char *DIRCMD = "";
- char *DELCMD = "";
- char *TYPCMD = "";
- char *SPACMD = "";
- char *SPACM2 = "";
- char *WHOCMD = "";
-
- /*
- Functions (n is one of the predefined file numbers from ckermi.h):
-
- zopeni(n,name) -- Opens an existing file for input.
- zopeno(n,name) -- Opens a new file for output.
- zclose(n) -- Closes a file.
- zchin(n) -- Gets the next character from an input file.
- zsout(n,s) -- Write a null-terminated string to output file.
- zsoutl(n,s) -- Like zsout, but appends a line terminator.
- zsoutx(n,s,x) -- Write x characters to output file.
- zchout(n,c) -- Add a character to an output file.
- zchki(name) -- Check if named file exists and is readable, ret size.
- zchko(name) -- Check if named file can be created.
- znewn(name,s) -- Make a new unique file name based on the given name.
- zdelet(name) -- Delete the named file.
- zxpand(string) -- NOT CURRENTLY SUPPORTED, returns file name unchanged.
- znext(string) -- Returns the next file from list in string.
- zxcmd(cmd) -- NOT CURRENTLY SUPPORTED
- zrtol(n1,n2) -- Convert remote filename into local form.
- zltor(n1,n2) -- Convert local filename into remote form.
- zchdir(dirnam) -- Change working directory.
- zhome() -- Return pointer to home directory name string.
- */
-
- /* Includes */
-
- #include "ctermi.h" /* Kermit definitions, ctype, stdio */
-
- #ifndef MAXNAMLEN
- #define MAXNAMLEN 50 /* If still not defined... */
- #endif
-
- #define MAXWLD 2 /* maximum wildcard filenames */
-
- /* Declarations */
-
- char *fp[ZNFILS]; /* array of pointers to BSWA's */
- char *fbuff[ZNFILS]; /* array of pointers to file buffers */
- static int erc;
- extern char bsvid[];
- static int fcount; /* number of files in wild group */
- static char *mtchs[MAXWLD], /* matches found for filename */
- **mtchptr; /* pointer to current match */
-
- /* Z O P E N I -- Open an existing file for input. */
-
- zopeni(n,name) int n; char *name; {
- debug(F111," zopeni",name,n);
- debug(F101," fp","", n);
- if (chkfn(n) != 0) return(0);
- if (n == ZSTDIO) { /* Standard input? */
- fprintf(stderr, "?Terminal input not allowed\n");
- debug(F110, "zopeni: attempts input from stdin","",0);
- return(0);
- }
- erc = allocmemorysl(130, &fp[n]);
- if (erc) { debug(F101,"zopeni - allocmemorysl of fp","", erc);
- perror("zopeni - allocmemorysl of fp");
- return(0);}
- erc = allocmemorysl(2048, &fbuff[n]);
- if (erc) { debug(F101,"zopeni - allocmemorysl of fbuff","", erc);
- perror("zopeni - allocmemorysl of fbuff");
- return(0);}
- erc = openbytestream(fp[n], name, strlen(name), 0l, 0, 0x6d72,
- fbuff[n], 2048);
- debug(F111," zopeni", name, n);
- if (erc != 0) perror("zopeni");
- return((erc == 0) ? 1 : 0);
- }
-
- /* Z O P E N O -- Open a new file for output. */
-
- zopeno(n,name) int n; char *name; {
- debug(F111," zopeno",name,n);
- debug(F101," fp","", n);
- if (chkfn(n) != 0) return(0);
- if ((n == ZCTERM) || (n == ZSTDIO)) { /* Terminal or standard output */
- fp[ZOFILE] = &bsvid[0];
- debug(F101," fp[]=stdout", "", n);
- return(1);
- }
- erc = allocmemorysl(130, &fp[n]);
- if (erc) { debug(F101,"zopeno - allocmemorysl of fp","", erc);
- perror("zopeno - allocmemorysl of fp");
- return(0);}
- erc = allocmemorysl(2048, &fbuff[n]);
- if (erc) { debug(F101,"zopeno - allocmemorysl of fbuff","", erc);
- perror("zopeno - allocmemorysl of fbuff");
- return(0);}
- erc = openbytestream(fp[n], name, strlen(name), 0l, 0, 0x6d77,
- fbuff[n], 2048);
- debug(F111," zopeno", name, n);
- if (erc != 0) perror("zopeno");
- return((erc == 0) ? 1 : 0);
- }
-
- /* Z C L O S E -- Close the given file. */
-
- zclose (n) int n; {
- if (chkfn(n) < 1) return(0);
- /* return(1); temp test code, receive works with this line in */
- erc = 0;
- if (fp[n] != &bsvid[0]) {
- if ((n != ZCTERM ) && (n != ZSTDIO)) {
- erc = closebytestream(fp[n]);
- }
- }
- fp[n] = NULL;
- if (erc == 0) return(1);
- else return(0);
- }
-
- /* Z C H I N -- Get a character from the input file. */
-
- zchin(n) int n; {
- int a;
- if (chkfn(n) < 1) return(-1);
- erc = readbyte(fp[n], &a);
- return((erc != 0) ? -1 : a & 0377);
- }
-
- /* Z S O U T -- Write a string to the given file. */
-
- zsout(n,s) int n; char *s; {
- int cbwritten;
- if (chkfn(n) < 1) return(-1);
- erc = writebsrecord(fp[n], s, strlen(s), &cbwritten);
- return(0);
- }
-
- /* Z S O U T L -- Write string to file, with line terminator */
-
- zsoutl(n,s) int n; char *s; {
- int cbwritten;
- if (chkfn(n) < 1) return(-1);
- erc = writebsrecord(fp[n], s, strlen(s), &cbwritten);
- erc = writebyte(fp[n], 0x0a);
- return(0);
- }
-
- /* Z S O U T X -- Write x characters to file */
-
- zsoutx(n,s,x) int n, x; char *s; {
- int i;
- if (chkfn(n) < 1) return(-1);
- for (i = 0; i < x; i++) erc = writebyte(fp[n], *s++);
- return(0);
- }
-
-
- /* Z C H O U T -- Add a character to the given file. */
-
- zchout(n,c) int n; char c; {
- if (chkfn(n) < 1) return(-1);
- erc = writebyte(fp[n], c);
- return(0);
- }
-
- /* C H K F N -- Internal function to verify file number is ok */
-
- /*
- Returns:
- -1: File number n is out of range
- 0: n is in range, but file is not open
- 1: n in range and file is open
- */
- chkfn(n) int n; {
- switch (n) {
- case ZCTERM:
- case ZSTDIO:
- case ZIFILE:
- case ZOFILE:
- case ZDFILE:
- case ZTFILE:
- case ZPFILE:
- case ZSFILE: break;
- default:
- debug(F101,"chkfn: file number out of range","",n);
- fprintf(stderr,"?File number out of range - %d\n",n);
- return(-1);
- }
- return( (fp[n] == NULL) ? 0 : 1 );
- }
-
- /* Z C H K I -- Check if input file exists and is readable */
-
- /*
- Returns:
- >= 0 if the file can be read (returns the size in Kbytes).
- -1 if file doesn't exist or can't be accessed,
- -2 if file exists but is not readable (e.g. a directory file).
- -3 if file exists but protected against read access.
- */
- zchki(name) char *name; {
- int fh;
- int erc;
- int erc2;
- long int filelenret;
- int filelen;
- erc = openfile(&fh, name, strlen(name), name, 0, 0x6d72);
- if (erc == 203) return(-1);
- if (erc == 219) return(-3);
- if (erc != 0) return(-2);
- erc = getfilestatus(fh, 0, &filelenret, 4);
- erc2 = closefile(fh);
- if (erc == 0)
- {
- filelenret /= 1024l;
- filelen = filelenret;
- if (!filelen) filelen = 1;
- return(filelen);
- }
- else return(-2);
-
- }
-
- /* Z C H K O -- Check if output file can be created */
-
- /*
- Returns -1 if write permission for the file would be denied, 0 otherwise.
- */
- zchko(name) char *name; {
- return(0);
- }
-
- /* Z D E L E T -- Delete the named file. */
-
- zdelet(name) char *name; {
- int fh;
- erc = openfile(&fh, name, strlen(name), name, 0, 0x6d6d);
- if (erc == 0) deletefile(fh);
- return(erc);
- }
-
-
- /* Z R T O L -- Convert remote filename into local form */
-
- /* For UNIX, this means changing uppercase letters to lowercase. */
-
- zrtol(name,name2) char *name, *name2; {
- for ( ; *name != '\0'; name++) {
- *name2++ = isupper(*name) ? tolower(*name) : *name;
- }
- *name2 = '\0';
- }
-
-
- /* Z L T O R -- Convert filename from local format to common form. */
-
- zltor(name,name2) char *name, *name2; {
- char work[100], *cp, *pp;
- int dc = 0;
-
- strcpy(work,name);
- for (cp = pp = work; *cp != '\0'; cp++) { /* strip path name */
- if (*cp == '/') {
- pp = cp;
- pp++;
- }
- else if (islower(*cp)) *cp = toupper(*cp); /* Uppercase letters */
- else if (*cp == '~') *cp = 'X'; /* Change tilde to 'X' */
- else if ((*cp == '.') && (++dc > 1)) *cp = 'X'; /* & extra dots */
- }
- cp = name2; /* If nothing before dot, */
- if (*pp == '.') *cp++ = 'X'; /* insert 'X' */
- strcpy(cp,pp);
- }
-
-
- /* Z X C M D -- Run a system command so its output can be read like a file
- ----- not implemented under CTOS */
-
- zxcmd(comand) char *comand; {
- return(0); /* return of any value less than 1 is considered a failure */
- }
-
- /* P E R R O R -- print error string */
- perror(s) char *s;
- {
- printf(s);
- putchar('\n');
- return(0);
- }
-
- /* zhome -- return a null pointer for CTOS */
- char *zhome() { return(NULL); }
-
- /* Z X P A N D -- Expand a wildcard string into an array of strings --
- WILDCARDS NOT YET SUPPORTED UNDER CTOS */
- zxpand(fn) char *fn;
- {
- static char fnbuff[50];
- strcpy(fnbuff, fn);
- mtchs[0] = &fnbuff[0];
- if (fnbuff[0] != '\0') fcount = 1;
- else fcount = 0;
- if (fcount > 0) mtchptr = mtchs; /* save pointer for next */
- debug(F111, "zxpand",mtchs[0],fcount);
- return(fcount);
- }
-
- /* Z N E W N -- Make a new name for the given file */
- znewn(fn,s) char *fn, **s;
- {
- static char buf[100];
- char *timeptr;
- char *rootname="CTOS-kermit";
- strcpy(buf, rootname);
- ztime(&timeptr);
- strcat(buf, timeptr);
- *s = buf;
- }
-
- /* Z N E X T -- Get the name of next file from list created by zxpand().
- Returns > 0 if there's another file, with its name copied
- into the arg string, or 0 if no more files in the list.
- */
- znext(fn) char *fn;
- {
- if (fcount-- > 0) strcpy(fn,*mtchptr++);
- else *fn = '\0';
- debug(F111, "znext",fn,fcount+1);
- return(fcount+1);
- }
-
- /* Z C H D I R -- Change directory, string of form [vol]<directory> */
- zchdir(dirnam)
-
- char *dirnam;
-
- {
- char ch;
- int namln = strlen(dirnam);
- int i;
- char *v, *d, *p;
- int vl=0, dl=0, pl=0;
- struct ucbtype
- {
- int reserved;
- char sizevol;
- char volname[12];
- char sizedir;
- char dirname[12];
- char sizepw;
- char password[12];
- } ucb;
-
- if ((ch = *dirnam++) != 0x5b) return(-1);
- v = dirnam;
- for (vl = 0; vl < namln; vl++)
- if ((ch = *dirnam++) == 0x5d) break;
- if ((ch = *dirnam++) != 0x3c) return(-1);
- d = dirnam;
- for (dl = 0; dl < namln-(vl+2); dl++)
- if ((ch = *dirnam++) == 0x3e) break;
- if (getucb(&ucb, sizeof(ucb))) return(-1);
- p = &ucb.password[0];
- pl = ucb.sizepw;
- if ((ch = *dirnam++) == 0x5e)
- {
- p = dirnam;
- for (pl = 0; pl < namln-(vl+dl+4); pl++)
- if ((ch = *dirnam++) == 0x00) break;
- }
- if (erc = setpath(v, vl, d, dl, p, pl)) return(-1);
- return(0);
- }
-
- /* zclosf -- close fork; return 0 for CTOS */
- zclosf() { return(0); }
-